import useEvent from '@/hooks/useEvent';
import { useState } from 'react';

type ReturnValue = [
  boolean,
  {
    toggle(): void;
    set: React.Dispatch<React.SetStateAction<boolean>>;
    setTrue(): void;
    setFalse(): void;
  }
];

export default function useBoolean(defaultValue = false): ReturnValue {
  const [bool, set] = useState(defaultValue);

  const toggle = useEvent(() => set(!bool));
  const setTrue = useEvent(() => set(true));
  const setFalse = useEvent(() => set(false));

  return [bool, { toggle, set, setTrue, setFalse }];
}
